package com.ujiuye.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.ujiuye.bean.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * ClassName: UserDao <br/>
 * Description: <br/>
 * date: 2021/9/16 11:04<br/>
 *
 * @author 荒<br />
 * @since JDK 1.8
 */
public class UserDao {
    QueryRunner qr = new QueryRunner(new ComboPooledDataSource());

    /**
     * 登录功能
     * @param username
     * @param password
     * @return
     */
    public User login(String username, String password) {
        String sql = "select * from book1 where username = ? and password = ?";
        try {
            return qr.query(sql,new BeanHandler<>(User.class),username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
